import * as types from './actionTypes'
import * as apiServer from 'api/list'

export const getList = () => (dispatch) => {
  dispatch({ type: types.SET_LOADING, data: true })
  apiServer
    .getList()
    .then((res) => {
      if (res.data.code === 200) {
        dispatch({
          type: types.SET_LIST,
          data: res.data.data
        })
      }
    })
    .finally(() => {
      dispatch({ type: types.SET_LOADING, data: false })
    })
}

export const delUsers = (id) => (dispatch) => {
  apiServer.delUser(id).then(() => {
    dispatch(getList())
  })
}

export const putUser = (params) => () => {
  apiServer.putUser(params)
}

export const addUser = (params) => () => {
  apiServer.addUser(params)
}
